<?php 
ArrowController::importModel("org.arrowplatform.controls.common.actions.ArrowAbstractUIAction");
ArrowController::importModel("smarty.SmartyCompiler");
class ArrowCustomHtmlAction extends ArrowAbstractUIAction{
	
	const STANDARD_CONTROLER = "/controller::actionRouter";
	
	private $compiler = null;
	
	public function configure(){
		parent::configure();
		$this->addProperties(array("transport" => false));
		$this->setContentCodeKept(true);
		$this->setDisplay(false);
		$this->setLazyInit(true);
	}
	
	/*public function generateBlockStartCode(){
		return "{literal}";
	}
	
	public function generateBlockEndCode(){
		return "{/literal}";
	}*/

	
	/*public function generateBlockStart(){
		$model = $this->getState("model");
		$this->compiler = new SmartyCompiler($this->getContentCode(),  ArrowView::getCurrentView()->ts);
		if($model){
			$class = ArrowModel::getModelClass( $model );
			$context = call_user_func(array( $class, "getByKey" ),$this->getState("key"), $class );
			$this->compiler->assign("context", $context);
		} 
		$this->compiler->assign("transport", $this->getProperty("transport"));
		return "" ;
	}*/
	/*
	public function generateBlockStart(){
		$model = $this->getState("model");
		$compiler = new SmartyCompiler($this->getContentCode(),  ArrowView::getCurrentView()->ts);
		if($model){
			$class = ArrowModel::getModelClass( $model );
			$context = call_user_func(array( $class, "getByKey" ),$this->getState("key"), $class );
			$compiler->assign("context", $context);
		}
		$compiler->assign("transport", $this->getProperty("transport"));
		return $compiler->getResult(array());
	}*/
	
	public function generateBlockEnd(){
		return "";
	}
	
	
	public function generate(  IArrowModel  $context = null ){
		$model = $this->getState("model");
		$content = $this->getContentCode() ;
		if($context){
			foreach($context as $key => $val){
				if(is_string($val))
					$content = str_replace("#".$key."#", $val, $content);
			}
		}
		
		//FB::error(print_r($context, 1), "dupa1");
		
		$this->compiler = new SmartyCompiler($content,  ArrowView::getCurrentView()->ts);

		if($model){
			$class = ArrowModel::getModelClass( $model );
			$context = call_user_func(array( $class, "getByKey" ),$this->getState("key"), $class );
			$this->compiler->assign("context", $context);
		} 
		
		$this->compiler->assign("transport", $this->getProperty("transport"));
		if( $context != null ) {
			$this->compiler->assign("context", $context);
		}
		foreach($this->getAllChildren() as $child){
			$child->init();
		}
		return $this->compiler->getResult(array());
		
	}

}

?>